<?php
namespace app\index\controller;

use think\Controller;
use app\index\logic\LoginLogic;

/**
 * 登录控制器
 * @author Alinejun666
 * Date 2018-8-22
 */
class Login extends controller
{
    public function index()
    {
		return $this->fetch('index');
    }

    public function regist()
    {
        if (request()->isAjax()) {
            $login = new LoginLogic();

            // 入参
            $data  = input("param.");
            // 验证信息
            $res = $this->validate($data, \app\index\validate\Login::class);
            if ($res !== true) {
                // 返回错误信息
                echo json_encode(msg_error($res));
                exit;
            }

            // 注册
            $res = $login->regist($data);
            echo $res;exit;

        }else{
            $this->error("发生错误", 'index/login/index');            
        }
    }


	public function login()
    {
        if (request()->isAjax()) {
            $login = new LoginLogic();

            // 入参
            $data  = input("param.");

            // 验证
            if (empty($data['username'])) {
                echo json_encode(msg_error("请输入用户名"));
                exit;
            }
            if (empty($data['password'])) {
                echo json_encode(msg_error("请输入密码"));
                exit;
            }

            // 登录
            $res = $login->login($data);
            echo $res;exit;

        }else{

            $this->error("发生错误", 'index/login/index');            
        }  
    }
}
